package com.culturalCenter.dataCenter.mapper.user;

import com.culturalCenter.dataCenter.customEntity.user.CustomListUser;
import com.culturalCenter.dataCenter.entity.user.*;
import com.culturalCenter.dataCenter.mapper.base.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    /**
     * 通过用户id查询
     *
     * @param userId
     *         用户id
     *
     * @return
     */
    List<User> queryByUserId(@Param("userId") String userId);

    List<CustomListUser> findCustomListUser(@Param("username") String username,@Param("branchId") String branchId);

    /**
     * 查询活跃用户列表
     *
     * @return
     */
    List<CustomListUser> selectActiveUserList();

    /**
     * 根据年龄区间统计人数
     *
     * @param startAge
     * @param endAge
     *
     * @return
     */
    int countByAge(@Param("startAge") int startAge, @Param("endAge") int endAge);

    /**
     * 根据日期统计本月本日新增人数
     *
     * @param date
     *
     * @return
     */
    UserDayNumber countByDay(@Param("date") Date date);

    /**
     * 批量插入数据
     *
     * @param collect
     */
    void insertBatch(List<User> collect);

    /**
     * 统计生肖
     *
     * @return
     */
    UserZodiacChina countByZodiacChina();

    /**
     * 统计星座
     *
     * @return
     */
    UserZodiacForeign countByZodiacForeign();

    /**
     * 统计用户类型
     *
     * @return
     */
    UserTypeCount countUserType();

    /**
     * 根据手机号查用户id和身份证
     *
     * @param phone
     *
     * @return
     */
    @Select("SELECT refId,IDCard FROM cdc_user WHERE phone = #{phone}")
    User queryUserIdAndIDCard(@Param("phone") String phone);

    /**
     * 用户总数
     *
     * @return
     */
    @Select("SELECT COUNT(1) FROM cdc_user")
    int getTotal();

    /**
     * 查本月新增用户数
     *
     * @return
     */
    @Select("SELECT COUNT(1) FROM cdc_user WHERE DATE_FORMAT(createTime,'%Y-%m')=DATE_FORMAT(NOW(),'%Y-%m')")
    int getThisMonthUsers();

    /**
     * 根据userId查user
     *
     * @param userId
     *
     * @return
     */
    @Select("SELECT * FROM cdc_user WHERE refId=#{userId}")
    User getByUserId(@Param("userId") String userId);

}
